<?php

namespace app\office\controller;

use think\Request;
use think\Db;
use app\office\controller\OfficeBase;
use app\office\model\Organization as OrganizationModel;
use app\office\model\Employee as EmployeeModel;
use app\office\model\Position as PositionModel;

class OrganizationEmployeePosition extends OfficeBase
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
      //验证Cookie↓
      $this->checkCookie();
      // 引入navbar
      $this->setNavbar();
      $this->assign('title',"组织机构-雇员-职位工程师列表");
      //获取组织机构列表
      // $organization=OrganizationModel::column('*','id');
      $organization=OrganizationModel::select();
      // dump($organization);
      // 循环获取组织机构对于员工列表
      foreach($organization as $k=>$v){
        $organizationList[$v->id]=$v;
        $organizationList[$v->id]['employee']=$v->employee;
        $temp=array();
        foreach($organizationList[$v->id]['employee'] as $kk=>$vv){
          $temp[$vv->id]=$vv;
          $temp[$vv->id]['position']=$vv->position;
        }
        $organizationList[$v->id]['employee']=$temp;
      }
      // dump($organizationList[34]['employee'][4]['position']);
      // $organizationList;
      $this->assign('organizationList',$organizationList);
      return $this->fetch();
        //
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index_organization_position()
    {
      //验证Cookie↓
      $this->checkCookie();
      // 引入navbar
      $this->setNavbar();
      $this->assign('title',"组织机构-雇员-职位工程师列表");
      //获取组织机构列表
      // $organization=OrganizationModel::column('*','id');
      $organization=OrganizationModel::select();
      // dump($organization);
      // 循环获取组织机构对于员工列表
      foreach($organization as $k=>$v){
        $organizationList[$v->id]=$v;
        $organizationList[$v->id]['employee']=$v->employee;
        //此处$organizationList[$v->id]['employee']是二维数组,分别对每个获取position
        $temp=array();
        foreach($organizationList[$v->id]['employee'] as $kk=>$vv){
          // 此处$vvv->position仍然是二维数组,需要进一步循环,获取每个position的id
          foreach($vv->position as $kkk=>$vvv){
            // 获取每个position的id及对于的position
            $temp[$vvv->id]=$vvv;
          }
        }
        $organizationList[$v->id]['position']=$temp;
      }
      $this->assign('organizationList',$organizationList);
      return $this->fetch();
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function create()
    {
        //
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save(Request $request)
    {
        //
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        //
    }

    /**
     * 显示编辑资源表单页.
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        //
    }
}
